<?php
include("check.php");
include_once("../function.php");
include_once("../class/bonus_class.php");
include_once("../class/ulevel_class.php");
include_once("../class/member_class.php");
include_once("../class/system_class.php");
header("Content-Type: text/html;charset=utf-8");
session_start();
$us=GetMemberbyID($_SESSION['ID']);
$_bonus_cl=new bonus_class();
$_ulevel_cl=new ulevel_class();
if ($_POST['submit']){
    $member_cl=new member_class();
    //  $ishk=ishk($us['usertel']);
    if($us['fenghao']==1){
        echo "<script language=javascript>alert('你已被封号,不能进行此操作.');window.location.href='?'</script>";
    }else{
        if ($sus=GetMemberbyNickname($_POST['nickname'])){
            if ($sus['ulevel']<$_POST['uplv']){
                if($sus['xlevel']==1){
                    echo "<script language=javascript>alert('您已超过升级时间,不能进行此操作.');window.location.href='?'</script>";
                }else {
                    $chaer = getulevelss($_POST['uplv']);
                    $cha = $chaer['lsk'] - $sus['lsk'];
                    //   $cha=$chaer['lsk']-$sus['lsk'];
                    /*        if($us['mey']>=$cha){
                                $num=1;
                            }*/
                    //    if($num>0){
                    $ulevelup['uid'] = $_SESSION['ID'];
                    $ulevelup['nickname'] = $us['nickname'];
                    $ulevelup['username'] = $us['username'];
                    $ulevelup['ylevel'] = $sus['ulevel'];
                    $ulevelup['uplevel'] = $_POST['uplv'];
                    $ulevelup['bdid'] = $us['bdid'];
                    $ulevelup['bdname'] = $us['bdname'];
                    $ulevelup['sid'] = $sus['id'];
                    $ulevelup['snickname'] = $sus['nickname'];
                    $ulevelup['susername'] = $sus['username'];
                    $ulevelup['udate'] = now();
                    $ulevelup['issh'] = 0;
                    $ulevelup['cha'] = $cha;
                    add_insert_cl('ulevelup', $ulevelup);


                    /*        $ul=ulevel($_POST['uplv']);
                            $sus_update['ulevel']=$ul['ulevel'];
                            $sus_update['lsk']=$ul['lsk'];
                            $sus_update['dan']=$ul['dan'];
                            $ispay=$sus['ispay'];
                            edit_update_cl('member',$sus_update,$sus['id']);*/
                    /*      if($num==1){
                              $us_update['mey']=$us['mey']-$cha;
                          }
                          edit_update_cl('member',$us_update,$us['id']);*/
                    echo "<script language=javascript>alert('升级申请中.');window.location.href='?'</script>";
                    /*   }else{
                           echo "<script language=javascript>alert('您的奖金币余额不足.');window.location.href='?'</script>";
                       }*/
                }
            }else{
                echo "<script language=javascript>alert('申请级别错误,该会员的级别已经超过所申请级别.');window.location.href='?'</script>";
            }

        }else{
            echo "<script language=javascript>alert('该会员不存在,请确认后重新输入.');window.location.href='?'</script>";
        }
    }

}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="./awesome/css/font-awesome.min.css"/>
    <link href="css/style1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="./he/jquery.ui.autocomplete.css">
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/style.js" type="text/javascript" charset="utf-8"></script>
    <title>升级操作</title>
    <script language="javascript">
        <!--
        function checknickname(lx)
        {
            var iframe = document.getElementById("iframe");
            var user =  document.getElementById("nickname");
            iframe.src= "checknickname.php?lx="+lx+"&nickname="+user.value;
        }
        -->
    </script>
</head>
<body>
<?php
$title="会员升级";
include_once("./public/header_nav.html");
?>
<iframe name="iframe" id="iframe" width="0" height="0" src="about:blank" style="display:none"></iframe>
<form name="form1" method="post" action="?" onSubmit="return CheckForm();">
    <table  width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
<!--        <tr>
            <td align="right">奖励积分余额:</td>
            <td><?/*=$us['mey']*/?></td>
        </tr>-->
        <tr>
            <td align="right">升级会员编号:</td>
            <td><input name="nickname" id="nickname" type="text">
                <input name="button4" type="button" class="button_blue" id="button4" onclick='checknickname(6);' value="验  证"><iframe name="iframe" id="iframe" width="0" height="0" src="about:blank" style="display:none"></iframe></td>
        </tr>
        <tr>
            <td width="46%" height="22" align="right">申请升级：</td>
            <td width="54%" align="left">
                <select name="uplv" id="uplv">
                    <?php
                    session_start();
                    $ulevel = $us['ulevel'];
                    $sql = "select * from ulevel where ulevel >= ".$us['ulevel']." ";
                    $result = mysql_query($sql);
                    while ($row = mysql_fetch_assoc($result)){?>
                        <option value='<?=$row['ulevel']?>'><?=$row['lvname']?></option>
                    <?php } ?>
                </select></td>
        </tr>
    </table>
    <table align="center" class="ziti" width="100%">
        <tr>
            <td align="center"><input name="submit" id="submit" type="submit" class="button_green" value="申 请 升 级" onClick="javascript:return confirm('您确认申请升级吗？');"></td>
        </tr>
    </table>
    <br>
    <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr>
            <td height="20" colspan="8" align="center"> 申 请 记 录</td>
        </tr>
        <tr>

            <td align="center">升级会员编号</td>
            <td align="center">升级会员姓名</td>
            <td align="center">原级别</td>
            <td align="center">申请级别</td>
            <td align="center">补单金额</td>
            <td align="center">申请时间</td>
            <td align="center">操作人编号</td>
            <td align="center">操作人姓名</td>
            <td  align="center">审核状态</td>
        </tr>
        <?php
        $pagesize = 10; //设置每页记录数
        $sql = "SELECT * FROM `ulevelup` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']."";
        if($query = mysql_query($sql)){
            $sum = mysql_num_rows($query); //计算总记录数
        }else{
            $sum=0;
        }
        if($sum % $pagesize == 0) //计算总页数
            $total = (int)($sum/$pagesize);
        else
            $total = (int)($sum/$pagesize) + 1;
        if (isset($_GET['page'])) //获得页码
        {
            $p = (int)$_GET['page'];
        }
        else
        {
            $p = 1;
        }
        if ($p>$total){
            $p=$total;
        }
        $start = $pagesize * ($p - 1); //计算起始记录
        $sql = "SELECT * FROM `ulevelup` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']." order by id desc limit ".$start.",".$pagesize;
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $yul=ulevel($row['ylevel']);
                $uul=ulevel($row['uplevel']);
                ?>
                <tr>

                    <td align="center"><?=$row['snickname']?></td>
                    <td align="center"><?=$row['susername']?></td>
                    <td align="center"><?=$yul['lvname']?></td>
                    <td align="center"><?=$uul['lvname']?></td>
                    <td align="center"><?=$row['cha']?></td>
                    <td align="center"><?=$row['udate']?></td>
                    <td align="center"><?=$row['nickname']?></td>
                    <td align="center"><?=$row['username']?></td>
                    <td align="center"><?php if ($row['issh']==1){?>通过审核<?php }elseif($row['issh']==2){?> <font color="#FF0000">未通过审核</font><?php }else{?> <font color="#FF0000">未审核</font><?php }?></td>
                </tr>
                <?php
            }
        }
        ?>
    </table>
    <table width="100%" border="0" class="ziti">
        <tr>
            <td align="left">&nbsp;</td>
            <td  style="padding-top: 0.4rem" align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
        </tr>
    </table>
</form>
<?php include_once ("public/footer_nav.html")?>
</body>
</html>